"""
@author: yqx
@file: data_hotcity.py
@time: 2024/8/7 17:15
"""


import data_get_url as geturl
import json
import csv
#城市  https://www.zhipin.com/wapi/zpgeek/common/data/city/site.json
urls="https://www.zhipin.com/wapi/zpgeek/common/data/city/site.json"
text=geturl.download(urls)
# 所有城市分类及编号
datacity=json.loads(text)
# print(datacity)
# 获取热门城市编号
hotcity=datacity["zpData"]["hotCitySites"]
# print(hotcity)
with open("hotcity.csv",'w',encoding='utf-8')as f:
    csvwriter=csv.writer(f)
    row_head=["城市","编号"]
    csvwriter.writerow(row_head)
    for citys in hotcity:
        # print(citys)
        # print(citys["code"])
        cs=citys["name"]
        bh=citys["code"]
        row_data=[cs,bh]
        csvwriter.writerow(row_data)
#     print("===================分隔符==============================")